/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Anthares
 */
@Entity
@Table(name = "LIGNE_COMMANDE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "LigneCommande.findAll", query = "SELECT l FROM LigneCommande l"),
    @NamedQuery(name = "LigneCommande.findByComId", query = "SELECT l FROM LigneCommande l WHERE l.ligneCommandePK.comId = :comId"),
    @NamedQuery(name = "LigneCommande.findByProdId", query = "SELECT l FROM LigneCommande l WHERE l.ligneCommandePK.prodId = :prodId"),
    @NamedQuery(name = "LigneCommande.findByQuantite", query = "SELECT l FROM LigneCommande l WHERE l.quantite = :quantite"),
    @NamedQuery(name = "LigneCommande.findByPrixReduit", query = "SELECT l FROM LigneCommande l WHERE l.prixReduit = :prixReduit")})
public class LigneCommande implements Serializable {
    private static final long serialVersionUID = 1L;

    @EmbeddedId
    protected LigneCommandePK ligneCommandePK;

    @Basic(optional = false)
    @NotNull
    @Min(value=1)
    @Column(nullable = false)
    private int quantite;

    @Min(value=0)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "PRIX_REDUIT", precision = 52)
    private Double prixReduit;

    @JoinColumn(name = "PROD_ID", referencedColumnName = "PROD_ID", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Produit produit;

    @JoinColumn(name = "COM_ID", referencedColumnName = "COM_ID", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Commande commande;

    public LigneCommande() {
    }

    public LigneCommande(LigneCommandePK ligneCommandePK) {
        this.ligneCommandePK = ligneCommandePK;
    }

    public LigneCommande(LigneCommandePK ligneCommandePK, int quantite) {
        this.ligneCommandePK = ligneCommandePK;
        this.quantite = quantite;
    }

    public LigneCommande(int comId, int prodId) {
        this.ligneCommandePK = new LigneCommandePK(comId, prodId);
    }

    public LigneCommandePK getLigneCommandePK() {
        return ligneCommandePK;
    }

    public void setLigneCommandePK(LigneCommandePK ligneCommandePK) {
        this.ligneCommandePK = ligneCommandePK;
    }

    public int getQuantite() {
        return quantite;
    }

    public void setQuantite(int quantite) {
        this.quantite = quantite;
    }

    public Double getPrixReduit() {
        return prixReduit;
    }

    public void setPrixReduit(Double prixReduit) {
        this.prixReduit = prixReduit;
    }

    public Produit getProduit() {
        return produit;
    }

    public void setProduit(Produit produit) {
        this.produit = produit;
    }

    public Commande getCommande() {
        return commande;
    }

    public void setCommande(Commande commande) {
        this.commande = commande;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ligneCommandePK != null ? ligneCommandePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LigneCommande)) {
            return false;
        }
        LigneCommande other = (LigneCommande) object;
        if ((this.ligneCommandePK == null && other.ligneCommandePK != null) || (this.ligneCommandePK != null && !this.ligneCommandePK.equals(other.ligneCommandePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Model.LigneCommande[ ligneCommandePK=" + ligneCommandePK + " ]";
    }
    
}
